package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Model;

import java.util.Date;
import java.util.List;

/**
 * Created by xiaojie on 15-11-11.
 */
public class OnlineCount extends Model<OnlineCount>{

    public static final OnlineCount dao = new OnlineCount();

    /**
     * 查询我的考试
     * @param studentId
     * @return
     */
    public List<OnlineCount> findByStudentIdAndDate(Long studentId, String year, String month, String day){
        return dao.find("select t.* from t_online_count t where t.student_id = ? and" +
                " t.year = ? and t.month = ? and t.day = ?",studentId,year,month,day);
    }
    public  void save(OnlineCount onlineCount,String year,String month,String day,Date time,Long studentId){
        onlineCount.set("year",year);
        onlineCount.set("month",month);
        onlineCount.set("day",day);
        onlineCount.set("online_time",0l);
        onlineCount.set("beginTime",time);
        onlineCount.set("student_id",studentId);
        onlineCount.remove("id").save();
    }
    public OnlineCount findbyStudentId(Long studentId){
        return dao.findFirst("select t.* from t_online_count t where t.student_id = ? order by t.beginTime desc",studentId);
    }
}
